package com.example.server.server;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author heyuduo
 * @date 2022/6/18 15:48
 */
@Slf4j
public class RpcServer {

    private ExecutorService executorService= Executors.newCachedThreadPool();

    public void  publishServer(final Map<String,Object> serviceRegistCenter, int port){
        ServerSocket serverSocket;
        try {
            serverSocket=new ServerSocket(port);
            log.info("服务端启动监听，端口=[{}]",port);
            while (true) {
                Socket socket=serverSocket.accept();
                log.info("服务端监听到新链接，客户端地址=【{}】",socket.getRemoteSocketAddress());
                executorService.execute(new RpcServerProcessor(socket,serviceRegistCenter));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}